home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / phpmyadmin / libraries / Config.class.php < prev    next >
Encoding:
PHP Script  |  2006-11-18  |  31.1 KB  |  991 lines

  1. <?php
  2. /* $Id: Config.class.php 9717 2006-11-17 10:05:59Z nijel $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. /**
  6.  * Configuration class
  7.  *
  8.  */
  9. class PMA_Config
  10. {
  11.     /**
  12.      * @var string  default config source
  13.      */
  14.     var $default_source = './libraries/config.default.php';
  15.  
  16.     /**
  17.      * @var array   configuration settings
  18.      */
  19.     var $settings = array();
  20.  
  21.     /**
  22.      * @var string  config source
  23.      */
  24.     var $source = '';
  25.  
  26.     /**
  27.      * @var int     source modification time
  28.      */
  29.     var $source_mtime = 0;
  30.     var $default_source_mtime = 0;
  31.  
  32.     /**
  33.      * @var boolean
  34.      */
  35.     var $error_config_file = false;
  36.  
  37.     /**
  38.      * @var boolean
  39.      */
  40.     var $error_config_default_file = false;
  41.  
  42.     /**
  43.      * @var boolean
  44.      */
  45.     var $error_pma_uri = false;
  46.  
  47.     /**
  48.      * @var array
  49.      */
  50.     var $default_server = array();
  51.  
  52.     /**
  53.      * @var boolean wether init is done or mot
  54.      * set this to false to force some initial checks
  55.      * like checking for required functions
  56.      */
  57.     var $done = false;
  58.  
  59.     /**
  60.      * constructor
  61.      *
  62.      * @param   string  source to read config from
  63.      */
  64.     function __construct($source = null)
  65.     {
  66.         $this->settings = array();
  67.  
  68.         // functions need to refresh in case of config file changed goes in
  69.         // PMA_Config::load()
  70.         $this->load($source);
  71.  
  72.         // other settings, independant from config file, comes in
  73.         $this->checkSystem();
  74.  
  75.         $this->checkIsHttps();
  76.     }
  77.  
  78.     /**
  79.      * sets system and application settings
  80.      */
  81.     function checkSystem()
  82.     {
  83.         $this->set('PMA_VERSION', '2.9.1.1');
  84.         /**
  85.          * @deprecated
  86.          */
  87.         $this->set('PMA_THEME_VERSION', 2);
  88.         /**
  89.          * @deprecated
  90.          */
  91.         $this->set('PMA_THEME_GENERATION', 2);
  92.  
  93.         $this->checkPhpVersion();
  94.         $this->checkWebServerOs();
  95.         $this->checkWebServer();
  96.         $this->checkGd2();
  97.         $this->checkClient();
  98.         $this->checkUpload();
  99.         $this->checkUploadSize();
  100.         $this->checkOutputCompression();
  101.     }
  102.  
  103.     /**
  104.      * wether to use gzip output compression or not
  105.      */
  106.     function checkOutputCompression()
  107.     {
  108.         // If zlib output compression is set in the php configuration file, no
  109.         // output buffering should be run
  110.         if (@ini_get('zlib.output_compression')) {
  111.             $this->set('OBGzip', false);
  112.         }
  113.  
  114.         // disable output-buffering (if set to 'auto') for IE6, else enable it.
  115.         if (strtolower($this->get('OBGzip')) == 'auto') {
  116.             if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE'
  117.               && $this->get('PMA_USR_BROWSER_VER') >= 6
  118.               && $this->get('PMA_USR_BROWSER_VER') < 7) {
  119.                 $this->set('OBGzip', false);
  120.             } else {
  121.                 $this->set('OBGzip', true);
  122.             }
  123.         }
  124.     }
  125.  
  126.     /**
  127.      * Determines platform (OS), browser and version of the user
  128.      * Based on a phpBuilder article:
  129.      * @see http://www.phpbuilder.net/columns/tim20000821.php
  130.      */
  131.     function checkClient()
  132.     {
  133.         if (PMA_getenv('HTTP_USER_AGENT')) {
  134.             $HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT');
  135.         } elseif (!isset($HTTP_USER_AGENT)) {
  136.             $HTTP_USER_AGENT = '';
  137.         }
  138.  
  139.         // 1. Platform
  140.         if (strstr($HTTP_USER_AGENT, 'Win')) {
  141.             $this->set('PMA_USR_OS', 'Win');
  142.         } elseif (strstr($HTTP_USER_AGENT, 'Mac')) {
  143.             $this->set('PMA_USR_OS', 'Mac');
  144.         } elseif (strstr($HTTP_USER_AGENT, 'Linux')) {
  145.             $this->set('PMA_USR_OS', 'Linux');
  146.         } elseif (strstr($HTTP_USER_AGENT, 'Unix')) {
  147.             $this->set('PMA_USR_OS', 'Unix');
  148.         } elseif (strstr($HTTP_USER_AGENT, 'OS/2')) {
  149.             $this->set('PMA_USR_OS', 'OS/2');
  150.         } else {
  151.             $this->set('PMA_USR_OS', 'Other');
  152.         }
  153.  
  154.         // 2. browser and version
  155.         // (must check everything else before Mozilla)
  156.  
  157.         if (preg_match('@Opera(/| )([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
  158.             $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
  159.             $this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
  160.         } elseif (preg_match('@MSIE ([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
  161.             $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
  162.             $this->set('PMA_USR_BROWSER_AGENT', 'IE');
  163.         } elseif (preg_match('@OmniWeb/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
  164.             $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
  165.             $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
  166.         //} elseif (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
  167.         // Konqueror 2.2.2 says Konqueror/2.2.2
  168.         // Konqueror 3.0.3 says Konqueror/3
  169.         } elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) {
  170.             $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
  171.             $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
  172.         } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)
  173.                    && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)) {
  174.             $this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]);
  175.             $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
  176.         } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
  177.             $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
  178.             $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
  179.         } else {
  180.             $this->set('PMA_USR_BROWSER_VER', 0);
  181.             $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
  182.         }
  183.     }
  184.  
  185.     /**
  186.      * Whether GD2 is present
  187.      */
  188.     function checkGd2()
  189.     {
  190.         if ($this->get('GD2Available') == 'yes') {
  191.             $this->set('PMA_IS_GD2', 1);
  192.         } elseif ($this->get('GD2Available') == 'no') {
  193.             $this->set('PMA_IS_GD2', 0);
  194.         } else {
  195.             if (!@extension_loaded('gd')) {
  196.                 PMA_dl('gd');
  197.             }
  198.             if (!@function_exists('imagecreatetruecolor')) {
  199.                 $this->set('PMA_IS_GD2', 0);
  200.             } else {
  201.                 if (@function_exists('gd_info')) {
  202.                     $gd_nfo = gd_info();
  203.                     if (strstr($gd_nfo["GD Version"], '2.')) {
  204.                         $this->set('PMA_IS_GD2', 1);
  205.                     } else {
  206.                         $this->set('PMA_IS_GD2', 0);
  207.                     }
  208.                 } else {
  209.                     /* We must do hard way... */
  210.                     ob_start();
  211.                     phpinfo(INFO_MODULES); /* Only modules */
  212.                     $a = strip_tags(ob_get_contents());
  213.                     ob_end_clean();
  214.                     /* Get GD version string from phpinfo output */
  215.                     if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
  216.                         if (strstr($v, '2.')) {
  217.                             $this->set('PMA_IS_GD2', 1);
  218.                         } else {
  219.                             $this->set('PMA_IS_GD2', 0);
  220.                         }
  221.                     } else {
  222.                         $this->set('PMA_IS_GD2', 0);
  223.                     }
  224.                 }
  225.             }
  226.         }
  227.     }
  228.  
  229.     /**
  230.      * Whether the Web server php is running on is IIS
  231.      */
  232.     function checkWebServer()
  233.     {
  234.         if (PMA_getenv('SERVER_SOFTWARE')
  235.           // some versions return Microsoft-IIS, some Microsoft/IIS
  236.           // we could use a preg_match() but it's slower
  237.           && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
  238.           && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) {
  239.             $this->set('PMA_IS_IIS', 1);
  240.         } else {
  241.             $this->set('PMA_IS_IIS', 0);
  242.         }
  243.     }
  244.  
  245.     /**
  246.      * Whether the os php is running on is windows or not
  247.      */
  248.     function checkWebServerOs()
  249.     {
  250.         // Default to Unix or Equiv
  251.         $this->set('PMA_IS_WINDOWS', 0);
  252.         // If PHP_OS is defined then continue
  253.         if (defined('PHP_OS')) {
  254.             if (stristr(PHP_OS, 'win') ) {
  255.                 // Is it some version of Windows
  256.                 $this->set('PMA_IS_WINDOWS', 1);
  257.             } elseif (stristr(PHP_OS, 'OS/2')) {
  258.                 // Is it OS/2 (No file permissions like Windows)
  259.                 $this->set('PMA_IS_WINDOWS', 1);
  260.             }
  261.         }
  262.     }
  263.  
  264.     /**
  265.      * detects PHP version
  266.      */
  267.     function checkPhpVersion()
  268.     {
  269.         $match = array();
  270.         if (! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
  271.                 phpversion(), $match)) {
  272.             $result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
  273.                 phpversion(), $match);
  274.         }
  275.         if (isset($match) && ! empty($match[1])) {
  276.             if (! isset($match[2])) {
  277.                 $match[2] = 0;
  278.             }
  279.             if (! isset($match[3])) {
  280.                 $match[3] = 0;
  281.             }
  282.             $this->set('PMA_PHP_INT_VERSION',
  283.                 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
  284.         } else {
  285.             $this->set('PMA_PHP_INT_VERSION', 0);
  286.         }
  287.         $this->set('PMA_PHP_STR_VERSION', phpversion());
  288.     }
  289.  
  290.     /**
  291.      * re-init object after loading from session file
  292.      * checks config file for changes and relaods if neccessary
  293.      */
  294.     function __wakeup()
  295.     {
  296.         if (! $this->checkConfigSource()
  297.           || $this->source_mtime !== filemtime($this->getSource())
  298.           || $this->default_source_mtime !== filemtime($this->default_source)
  299.           || $this->error_config_file
  300.           || $this->error_config_default_file) {
  301.             $this->settings = array();
  302.             $this->load();
  303.             $this->checkSystem();
  304.         }
  305.  
  306.         // check for https needs to be done everytime,
  307.         // as https and http uses same session so this info can not be stored
  308.         // in session
  309.         $this->checkIsHttps();
  310.  
  311.         $this->checkCollationConnection();
  312.         $this->checkFontsize();
  313.     }
  314.  
  315.     /**
  316.      * loads default values from default source
  317.      *
  318.      * @uses    file_exists()
  319.      * @uses    $this->default_source
  320.      * @uses    $this->error_config_default_file
  321.      * @uses    $this->settings
  322.      * @return  boolean     success
  323.      */
  324.     function loadDefaults()
  325.     {
  326.         $cfg = array();
  327.         if (! file_exists($this->default_source)) {
  328.             $this->error_config_default_file = true;
  329.             return false;
  330.         }
  331.         include $this->default_source;
  332.  
  333.         $this->default_source_mtime = filemtime($this->default_source);
  334.  
  335.         $this->default_server = $cfg['Servers'][1];
  336.         unset($cfg['Servers']);
  337.  
  338.         $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
  339.  
  340.         $this->error_config_default_file = false;
  341.  
  342.         return true;
  343.     }
  344.  
  345.     /**
  346.      * loads configuration from $source, usally the config file
  347.      * should be called on object creation and from __wakeup if config file
  348.      * has changed
  349.      *
  350.      * @param   string $source  config file
  351.      */
  352.     function load($source = null)
  353.     {
  354.         $this->loadDefaults();
  355.  
  356.         if (null !== $source) {
  357.             $this->setSource($source);
  358.         }
  359.  
  360.         if (! $this->checkConfigSource()) {
  361.             return false;
  362.         }
  363.  
  364.         $cfg = array();
  365.  
  366.         /**
  367.          * Parses the configuration file
  368.          */
  369.         $old_error_reporting = error_reporting(0);
  370.         if (function_exists('file_get_contents')) {
  371.             $eval_result =
  372.                 eval('?>' . trim(file_get_contents($this->getSource())));
  373.         } else {
  374.             $eval_result =
  375.                 eval('?>' . trim(implode("\n", file($this->getSource()))));
  376.         }
  377.         error_reporting($old_error_reporting);
  378.  
  379.         if ($eval_result === false) {
  380.             $this->error_config_file = true;
  381.         } else  {
  382.             $this->error_config_file = false;
  383.             $this->source_mtime = filemtime($this->getSource());
  384.         }
  385.  
  386.         /**
  387.          * @TODO check validity of $_COOKIE['pma_collation_connection']
  388.          */
  389.         if (! empty($_COOKIE['pma_collation_connection'])) {
  390.             $this->set('collation_connection',
  391.                 strip_tags($_COOKIE['pma_collation_connection']));
  392.         } else {
  393.             $this->set('collation_connection',
  394.                 $this->get('DefaultConnectionCollation'));
  395.         }
  396.  
  397.         $this->checkCollationConnection();
  398.         $this->checkFontsize();
  399.         //$this->checkPmaAbsoluteUri();
  400.         $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
  401.         return true;
  402.     }
  403.  
  404.     /**
  405.      * set source
  406.      * @param   string  $source
  407.      */
  408.     function setSource($source)
  409.     {
  410.         $this->source = trim($source);
  411.     }
  412.  
  413.     /**
  414.      * checks if the config folder still exists and terminates app if true
  415.      */
  416.     function checkConfigFolder()
  417.     {
  418.         // Refuse to work while there still might be some world writable dir:
  419.         if (is_dir('./config')) {
  420.             die('Remove "./config" directory before using phpMyAdmin!');
  421.         }
  422.     }
  423.  
  424.     /**
  425.      * check config source
  426.      *
  427.      * @return  boolean wether source is valid or not
  428.      */
  429.     function checkConfigSource()
  430.     {
  431.         if (! $this->getSource()) {
  432.             // no configuration file set at all
  433.             return false;
  434.         }
  435.  
  436.         if (! file_exists($this->getSource())) {
  437.             // do not trigger error here
  438.             // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
  439.             /*
  440.             trigger_error(
  441.                 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
  442.                 E_USER_WARNING);
  443.             */
  444.             $this->source_mtime = 0;
  445.             return false;
  446.         }
  447.  
  448.         if (! is_readable($this->getSource())) {
  449.             $this->source_mtime = 0;
  450.             die('Existing configuration file (' . $this->getSource() . ') is not readable.');
  451.         }
  452.  
  453.         // Check for permissions (on platforms that support it):
  454.         $perms = @fileperms($this->getSource());
  455.         if (!($perms === false) && ($perms & 2)) {
  456.             // This check is normally done after loading configuration
  457.             $this->checkWebServerOs();
  458.             if ($this->get('PMA_IS_WINDOWS') == 0) {
  459.                 $this->source_mtime = 0;
  460.                 die('Wrong permissions on configuration file, should not be world writable!');
  461.             }
  462.         }
  463.  
  464.         return true;
  465.     }
  466.  
  467.     /**
  468.      * returns specific config setting
  469.      * @param   string  $setting
  470.      * @return  mixed   value
  471.      */
  472.     function get($setting)
  473.     {
  474.         if (isset($this->settings[$setting])) {
  475.             return $this->settings[$setting];
  476.         }
  477.         return null;
  478.     }
  479.  
  480.     /**
  481.      * sets configuration variable
  482.      *
  483.      * @uses    $this->settings
  484.      * @param   string  $setting    configuration option
  485.      * @param   string  $value      new value for configuration option
  486.      */
  487.     function set($setting, $value)
  488.     {
  489.         $this->settings[$setting] = $value;
  490.     }
  491.  
  492.     /**
  493.      * returns source for current config
  494.      * @return  string  config source
  495.      */
  496.     function getSource()
  497.     {
  498.         return $this->source;
  499.     }
  500.  
  501.     /**
  502.      * old PHP 4 style constructor
  503.      *
  504.      * @deprecated
  505.      */
  506.     function PMA_Config($source = null)
  507.     {
  508.         $this->__construct($source);
  509.     }
  510.  
  511.     /**
  512.      * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
  513.      * set properly and, depending on browsers, inserting or updating a
  514.      * record might fail
  515.      */
  516.     function checkPmaAbsoluteUri()
  517.     {
  518.         // Setup a default value to let the people and lazy syadmins work anyway,
  519.         // they'll get an error if the autodetect code doesn't work
  520.         $pma_absolute_uri = $this->get('PmaAbsoluteUri');
  521.         $is_https = $this->get('is_https');
  522.         if (strlen($pma_absolute_uri) < 5
  523.             // needed to catch http/https switch
  524.             || ($is_https && substr($pma_absolute_uri, 0, 6) != 'https:')
  525.             || (!$is_https && substr($pma_absolute_uri, 0, 5) != 'http:')
  526.         ) {
  527.             $url = array();
  528.  
  529.             // At first we try to parse REQUEST_URI, it might contain full URL
  530.             if (PMA_getenv('REQUEST_URI')) {
  531.                 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
  532.                 if ($url === false) {
  533.                     $url = array( 'path' => $_SERVER['REQUEST_URI'] );
  534.                 }
  535.             }
  536.  
  537.             // If we don't have scheme, we didn't have full URL so we need to
  538.             // dig deeper
  539.             if (empty($url['scheme'])) {
  540.                 // Scheme
  541.                 if (PMA_getenv('HTTP_SCHEME')) {
  542.                     $url['scheme'] = PMA_getenv('HTTP_SCHEME');
  543.                 } else {
  544.                     $url['scheme'] =
  545.                         PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
  546.                             ? 'https'
  547.                             : 'http';
  548.                 }
  549.  
  550.                 // Host and port
  551.                 if (PMA_getenv('HTTP_HOST')) {
  552.                     if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) {
  553.                         list($url['host'], $url['port']) =
  554.                             explode(':', PMA_getenv('HTTP_HOST'));
  555.                     } else {
  556.                         $url['host'] = PMA_getenv('HTTP_HOST');
  557.                     }
  558.                 } elseif (PMA_getenv('SERVER_NAME')) {
  559.                     $url['host'] = PMA_getenv('SERVER_NAME');
  560.                 } else {
  561.                     $this->error_pma_uri = true;
  562.                     return false;
  563.                 }
  564.  
  565.                 // If we didn't set port yet...
  566.                 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
  567.                     $url['port'] = PMA_getenv('SERVER_PORT');
  568.                 }
  569.  
  570.                 // And finally the path could be already set from REQUEST_URI
  571.                 if (empty($url['path'])) {
  572.                     if (PMA_getenv('PATH_INFO')) {
  573.                         $path = parse_url(PMA_getenv('PATH_INFO'));
  574.                     } else {
  575.                         // PHP_SELF in CGI often points to cgi executable, so use it
  576.                         // as last choice
  577.                         $path = parse_url(PMA_getenv('PHP_SELF'));
  578.                     }
  579.                     $url['path'] = $path['path'];
  580.                 }
  581.             }
  582.  
  583.             // Make url from parts we have
  584.             $pma_absolute_uri = $url['scheme'] . '://';
  585.             // Was there user information?
  586.             if (!empty($url['user'])) {
  587.                 $pma_absolute_uri .= $url['user'];
  588.                 if (!empty($url['pass'])) {
  589.                     $pma_absolute_uri .= ':' . $url['pass'];
  590.                 }
  591.                 $pma_absolute_uri .= '@';
  592.             }
  593.             // Add hostname
  594.             $pma_absolute_uri .= $url['host'];
  595.             // Add port, if it not the default one
  596.             if (! empty($url['port'])
  597.               && (($url['scheme'] == 'http' && $url['port'] != 80)
  598.                 || ($url['scheme'] == 'https' && $url['port'] != 443))) {
  599.                 $pma_absolute_uri .= ':' . $url['port'];
  600.             }
  601.             // And finally path, without script name, the 'a' is there not to
  602.             // strip our directory, when path is only /pmadir/ without filename.
  603.             // Backslashes returned by Windows have to be changed.
  604.             // Only replace backslashes by forward slashes if on Windows,
  605.             // as the backslash could be valid on a non-Windows system.
  606.             if ($this->get('PMA_IS_WINDOWS') == 1) {
  607.                 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
  608.             } else {
  609.                 $path = dirname($url['path'] . 'a');
  610.             }
  611.  
  612.             // To work correctly within transformations overview:
  613.             if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
  614.                 if ($this->get('PMA_IS_WINDOWS') == 1) {
  615.                     $path = str_replace("\\", "/", dirname(dirname($path)));
  616.                 } else {
  617.                     $path = dirname(dirname($path));
  618.                 }
  619.             }
  620.             // in vhost situations, there could be already an ending slash
  621.             if (substr($path, -1) != '/') {
  622.                 $path .= '/';
  623.             }
  624.             $pma_absolute_uri .= $path;
  625.  
  626.             // We used to display a warning if PmaAbsoluteUri wasn't set, but now
  627.             // the autodetect code works well enough that we don't display the
  628.             // warning at all. The user can still set PmaAbsoluteUri manually.
  629.             // See
  630.             // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
  631.  
  632.         } else {
  633.             // The URI is specified, however users do often specify this
  634.             // wrongly, so we try to fix this.
  635.  
  636.             // Adds a trailing slash et the end of the phpMyAdmin uri if it
  637.             // does not exist.
  638.             if (substr($pma_absolute_uri, -1) != '/') {
  639.                 $pma_absolute_uri .= '/';
  640.             }
  641.  
  642.             // If URI doesn't start with http:// or https://, we will add
  643.             // this.
  644.             if (substr($pma_absolute_uri, 0, 7) != 'http://'
  645.               && substr($pma_absolute_uri, 0, 8) != 'https://') {
  646.                 $pma_absolute_uri =
  647.                     (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
  648.                         ? 'https'
  649.                         : 'http')
  650.                     . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
  651.                     . $pma_absolute_uri;
  652.             }
  653.         }
  654.  
  655.         $this->set('PmaAbsoluteUri', $pma_absolute_uri);
  656.     }
  657.  
  658.     /**
  659.      * check selected collation_connection
  660.      * @TODO check validity of $_REQUEST['collation_connection']
  661.      */
  662.     function checkCollationConnection()
  663.     {
  664.         // (could be improved by executing it after the MySQL connection only if
  665.         //  PMA_MYSQL_INT_VERSION >= 40100)
  666.         if (! empty($_REQUEST['collation_connection'])) {
  667.             $this->set('collation_connection',
  668.                 strip_tags($_REQUEST['collation_connection']));
  669.         }
  670.     }
  671.  
  672.     /**
  673.      * checks for font size configuration, and sets font size as requested by user
  674.      *
  675.      * @uses    $_GET
  676.      * @uses    $_POST
  677.      * @uses    $_COOKIE
  678.      * @uses    preg_match()
  679.      * @uses    function_exists()
  680.      * @uses    PMA_Config::set()
  681.      * @uses    PMA_Config::get()
  682.      * @uses    PMA_setCookie()
  683.      */
  684.     function checkFontsize()
  685.     {
  686.         $new_fontsize = '';
  687.  
  688.         if (isset($_GET['fontsize'])) {
  689.             $new_fontsize = $_GET['fontsize'];
  690.         } elseif (isset($_POST['fontsize'])) {
  691.             $new_fontsize = $_POST['fontsize'];
  692.         } elseif (isset($_COOKIE['pma_fontsize'])) {
  693.             $new_fontsize = $_COOKIE['pma_fontsize'];
  694.         }
  695.  
  696.         if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
  697.             $this->set('fontsize', $new_fontsize);
  698.         } elseif (! $this->get('fontsize')) {
  699.             $this->set('fontsize', '100%');
  700.         }
  701.  
  702.         if (function_exists('PMA_setCookie')) {
  703.             PMA_setCookie('pma_fontsize', $this->get('fontsize'), '100%');
  704.         }
  705.     }
  706.  
  707.     /**
  708.      * checks if upload is enabled
  709.      *
  710.      */
  711.     function checkUpload()
  712.     {
  713.         $this->set('enable_upload', true);
  714.         if (strtolower(@ini_get('file_uploads')) == 'off'
  715.           || @ini_get('file_uploads') == 0) {
  716.             $this->set('enable_upload', false);
  717.         }
  718.     }
  719.  
  720.     /**
  721.      * Maximum upload size as limited by PHP
  722.      * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
  723.      *
  724.      * this section generates $max_upload_size in bytes
  725.      */
  726.     function checkUploadSize()
  727.     {
  728.         if (! $filesize = ini_get('upload_max_filesize')) {
  729.             $filesize = "5M";
  730.         }
  731.  
  732.         if ($postsize = ini_get('post_max_size')) {
  733.             $this->set('max_upload_size',
  734.                 min(get_real_size($filesize), get_real_size($postsize)));
  735.         } else {
  736.             $this->set('max_upload_size', get_real_size($filesize));
  737.         }
  738.     }
  739.  
  740.     /**
  741.      * check for https
  742.      */
  743.     function checkIsHttps()
  744.     {
  745.         $this->set('is_https', PMA_Config::isHttps());
  746.     }
  747.  
  748.     /**
  749.      * @static
  750.      */
  751.     function isHttps()
  752.     {
  753.         $is_https = false;
  754.  
  755.         $url = array();
  756.  
  757.         // At first we try to parse REQUEST_URI, it might contain full URL,
  758.         if (PMA_getenv('REQUEST_URI')) {
  759.             $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
  760.             if($url === false) {
  761.                 $url = array();
  762.             }
  763.         }
  764.  
  765.         // If we don't have scheme, we didn't have full URL so we need to
  766.         // dig deeper
  767.         if (empty($url['scheme'])) {
  768.             // Scheme
  769.             if (PMA_getenv('HTTP_SCHEME')) {
  770.                 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
  771.             } else {
  772.                 $url['scheme'] =
  773.                     PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
  774.                         ? 'https'
  775.                         : 'http';
  776.             }
  777.         }
  778.  
  779.         if (isset($url['scheme'])
  780.           && $url['scheme'] == 'https') {
  781.             $is_https = true;
  782.         } else {
  783.             $is_https = false;
  784.         }
  785.  
  786.         return $is_https;
  787.     }
  788.  
  789.     /**
  790.      * detect correct cookie path
  791.      */
  792.     function checkCookiePath()
  793.     {
  794.         $this->set('cookie_path', PMA_Config::getCookiePath());
  795.     }
  796.  
  797.     /**
  798.      * @static
  799.      */
  800.     function getCookiePath()
  801.     {
  802.         static $cookie_path = null;
  803.  
  804.         if (null !== $cookie_path) {
  805.             return $cookie_path;
  806.         }
  807.  
  808.         $url = '';
  809.  
  810.         if (PMA_getenv('REQUEST_URI')) {
  811.             $url = PMA_getenv('REQUEST_URI');
  812.         }
  813.  
  814.         // If we don't have path
  815.         if (empty($url)) {
  816.             if (PMA_getenv('PATH_INFO')) {
  817.                 $url = PMA_getenv('PATH_INFO');
  818.             } elseif (PMA_getenv('PHP_SELF')) {
  819.                 // PHP_SELF in CGI often points to cgi executable, so use it
  820.                 // as last choice
  821.                 $url = PMA_getenv('PHP_SELF');
  822.             } elseif (PMA_getenv('SCRIPT_NAME')) {
  823.                 $url = PMA_getenv('PHP_SELF');
  824.             }
  825.         }
  826.  
  827.         $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
  828.         if ($parsed_url === false) {
  829.             $parsed_url = array('path' => $url);
  830.         }
  831.  
  832.         $cookie_path   = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/'))  . '/';
  833.  
  834.         return $cookie_path;
  835.     }
  836.  
  837.     /**
  838.      * enables backward compatibility
  839.      */
  840.     function enableBc()
  841.     {
  842.         $GLOBALS['cfg']             =& $this->settings;
  843.         $GLOBALS['default_server']  =& $this->default_server;
  844.         $GLOBALS['collation_connection'] = $this->get('collation_connection');
  845.         $GLOBALS['is_upload']       = $this->get('enable_upload');
  846.         $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
  847.         $GLOBALS['cookie_path']     = $this->get('cookie_path');
  848.         $GLOBALS['is_https']        = $this->get('is_https');
  849.  
  850.         $defines = array(
  851.             'PMA_VERSION',
  852.             'PMA_THEME_VERSION',
  853.             'PMA_THEME_GENERATION',
  854.             'PMA_PHP_STR_VERSION',
  855.             'PMA_PHP_INT_VERSION',
  856.             'PMA_IS_WINDOWS',
  857.             'PMA_IS_IIS',
  858.             'PMA_IS_GD2',
  859.             'PMA_USR_OS',
  860.             'PMA_USR_BROWSER_VER',
  861.             'PMA_USR_BROWSER_AGENT',
  862.             );
  863.  
  864.         foreach ($defines as $define) {
  865.             if (! defined($define)) {
  866.                 define($define, $this->get($define));
  867.             }
  868.         }
  869.     }
  870.  
  871.     /**
  872.      * @todo finish
  873.      */
  874.     function save() {}
  875.  
  876.     /**
  877.      * returns options for font size selection
  878.      *
  879.      * @uses    preg_replace()
  880.      * @uses    ksort()
  881.      * @static
  882.      * @param   string  $current_size   current selected font size with unit
  883.      * @return  array   selectable font sizes
  884.      */
  885.     function getFontsizeOptions($current_size = '100%')
  886.     {
  887.         $unit = preg_replace('/[0-9.]*/', '', $current_size);
  888.         $value = preg_replace('/[^0-9.]*/', '', $current_size);
  889.  
  890.         $factors = array();
  891.         $options = array();
  892.         $options["$value"] = $value . $unit;
  893.  
  894.         if ($unit === '%') {
  895.             $factors[] = 1;
  896.             $factors[] = 5;
  897.             $factors[] = 10;
  898.         } elseif ($unit === 'em') {
  899.             $factors[] = 0.05;
  900.             $factors[] = 0.2;
  901.             $factors[] = 1;
  902.         } elseif ($unit === 'pt') {
  903.             $factors[] = 0.5;
  904.             $factors[] = 2;
  905.         } elseif ($unit === 'px') {
  906.             $factors[] = 1;
  907.             $factors[] = 5;
  908.             $factors[] = 10;
  909.         } else {
  910.             //unknown font size unit
  911.             $factors[] = 0.05;
  912.             $factors[] = 0.2;
  913.             $factors[] = 1;
  914.             $factors[] = 5;
  915.             $factors[] = 10;
  916.         }
  917.  
  918.         foreach ($factors as $key => $factor) {
  919.             $option_inc = $value + $factor;
  920.             $option_dec = $value - $factor;
  921.             while (count($options) < 21) {
  922.                 $options["$option_inc"] = $option_inc . $unit;
  923.                 if ($option_dec > $factors[0]) {
  924.                     $options["$option_dec"] = $option_dec . $unit;
  925.                 }
  926.                 $option_inc += $factor;
  927.                 $option_dec -= $factor;
  928.                 if (isset($factors[$key + 1])
  929.                  && $option_inc >= $value + $factors[$key + 1]) {
  930.                     break;
  931.                 }
  932.             }
  933.         }
  934.         ksort($options);
  935.         return $options;
  936.     }
  937.  
  938.     /**
  939.      * returns html selectbox for font sizes
  940.      *
  941.      * @uses    $_SESSION['PMA_Config']
  942.      * @uses    PMA_Config::get()
  943.      * @uses    PMA_Config::getFontsizeOptions()
  944.      * @uses    $GLOBALS['strFontSize']
  945.      * @static
  946.      * @param   string  $current_size   currently slected font size with unit
  947.      * @return  string  html selectbox
  948.      */
  949.     function getFontsizeSelection()
  950.     {
  951.         $current_size = $_SESSION['PMA_Config']->get('fontsize');
  952.         $options = PMA_Config::getFontsizeOptions($current_size);
  953.  
  954.         $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
  955.         $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
  956.         foreach ($options as $option) {
  957.             $return .= '<option value="' . $option . '"';
  958.             if ($option == $current_size) {
  959.                 $return .= ' selected="selected"';
  960.             }
  961.             $return .= '>' . $option . '</option>' . "\n";
  962.         }
  963.         $return .= '</select>';
  964.  
  965.         return $return;
  966.     }
  967.  
  968.     /**
  969.      * return complete font size selection form
  970.      *
  971.      * @uses    PMA_generate_common_hidden_inputs()
  972.      * @uses    PMA_Config::getFontsizeSelection()
  973.      * @uses    $GLOBALS['strGo']
  974.      * @static
  975.      * @param   string  $current_size   currently slected font size with unit
  976.      * @return  string  html selectbox
  977.      */
  978.     function getFontsizeForm()
  979.     {
  980.         return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
  981.             . ' method="post" action="index.php" target="_parent">' . "\n"
  982.             . PMA_generate_common_hidden_inputs() . "\n"
  983.             . PMA_Config::getFontsizeSelection() . "\n"
  984.             . '<noscript>' . "\n"
  985.             . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
  986.             . '</noscript>' . "\n"
  987.             . '</form>';
  988.     }
  989. }
  990. ?>
  991.